#ifndef __STATUS_GRPC_CLIENT_H__
#define __STATUS_GRPC_CLIENT_H__

#include "../protos/message.grpc.pb.h"
#include "../NetGlobal.h"
#include "../ConfigMgr.h"

#include <memory>
#include <queue>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <grpcpp/grpcpp.h>

using message::GetChatServerReq;
using message::GetChatServerRsp;
using message::LoginReq;
using message::LoginRsp;
using message::StatusService;


class StatusConPool;

class StatusGrpcClient
{
public:
    StatusGrpcClient();
	GetChatServerRsp GetChatServerInfo(uint32_t uid);
    LoginRsp Login(uint32_t uid, std::string& token);

private:
    std::unique_ptr<StatusConPool> _pool;
};

class StatusConPool
{
public:
    StatusConPool(size_t poolSize, std::string host, std::string port);
    ~StatusConPool();
    std::unique_ptr<StatusService::Stub> getConnection();
    void returnConnection(std::unique_ptr<StatusService::Stub> context);
    void Close();

private:
    std::atomic_bool _isStop;
    size_t _poolSize;
    std::string _host;
    std::string _port;
    std::queue<std::unique_ptr<StatusService::Stub>> _connections;
    std::mutex _mutex;
    std::condition_variable _cond;
};


#endif // !__STATUS_GRPC_CLIENT_H__